﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.Connection;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL
{
    class HDBan
    {
        private dbConnection Conn;

        public HDBan()
        {
            Conn = new dbConnection();
        }

        public DataTable SelectAll()
        {
            return Conn.excuteSelectProcedureQuery("SelectAll_HDBan");
        }

        public DataTable SelectID(int MaHDBan)
        {
            SqlParameter[] SqlPara = new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@MaHDBan", SqlDbType.Int);
            SqlPara[0].Value = MaHDBan;
            return Conn.excuteSelectProcedureQuery("SelectID_HDBan", SqlPara);
        }

        public bool Insert(int MaNV, int MaKH, DateTime NgayLap)
        {
            SqlParameter[] SqlPara=new SqlParameter[3];
            SqlPara[0] = new SqlParameter("@MaNV", SqlDbType.Int);
            SqlPara[0].Value = MaNV;
            SqlPara[1] = new SqlParameter("@MaKH", SqlDbType.Int);
            SqlPara[1].Value = MaKH;
            SqlPara[2] = new SqlParameter("@NgayLap",SqlDbType.Date);
            SqlPara[2].Value = NgayLap;
            return Conn.executeInsertProcedureQuery("Insert_HDBan",SqlPara);
        }

        public bool Update(int MaHDBan, int MaNV, int MaKH, DateTime NgayLap)
        {
            SqlParameter[] SqlPara = new SqlParameter[4];
            SqlPara[0] = new SqlParameter("@MaHDBan",SqlDbType.Int);
            SqlPara[0].Value = MaHDBan;
            SqlPara[1] = new SqlParameter("@MaNV", SqlDbType.Int);
            SqlPara[1].Value = MaNV;
            SqlPara[2] = new SqlParameter("@MaKH", SqlDbType.Int);
            SqlPara[2].Value = MaKH;
            SqlPara[3] = new SqlParameter("@NgayLap", SqlDbType.Date);
            SqlPara[3].Value = NgayLap;
            return Conn.executeUpdateProcedureQuery("Update_HDBan",SqlPara);
        }

        public bool Delete(int MaHDBan)
        { 
            SqlParameter[] SqlPara=new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@MaHDBan",SqlDbType.Int);
            SqlPara[0].Value = MaHDBan;
            return Conn.executeDeleteProcedureQuery("Delete_HDBan",SqlPara);
        }
    }
}
